# -*- coding: utf-8 -*-
"""
@Time ： 2023/4/15 20:26
@Auth ： 叶东宇
@File ：HappyNumber.py
"""
import math


def happyNumber(n):
    sumTmp = 0
    lis = []
    while sumTmp not in lis:
        lis.append(sumTmp)
        sumTmp = numberSum(n)
        n = sumTmp
    lis.append(sumTmp)
    if sumTmp != 1:
        print(lis)
        return False
    else:
        print(lis)
        return True


def numberSum(n):
    sumNumber = 0
    l = len(str(n))
    for i in range(l, 0, -1):
        sumNumber += (n // math.pow(10,i-1)) ** 2
        n %= math.pow(10, i-1)
    return sumNumber

def from_leetcode(num):
    a = set()
    while True:
        tmp = getSum(num)
        if tmp == 1:
            return True
        else:
            if tmp in a:
                return False
        a.add(tmp)
        num = tmp
def getSum(num):
    sumTMP = 0
    while num:
        sumTMP += (num - (num // 10)*10) ** 2
        num = num // 10
    return sumTMP

def getNumberList(num):
    lis = []
    while num:
        lis.append(num % 10) # 取模
        num = num // 10
    return lis

if __name__ == "__main__":
    num = 10
    tmp = getNumberList(num)
    print(tmp)
    tmp.reverse()
    print(tmp)
    n = 19
    print(from_leetcode(n))
